#ifndef DSPNASM_SYMBOLCOLLECTOR_H
#define DSPNASM_SYMBOLCOLLECTOR_H

#include "NasmBaseVisitor.h"
#include "nasm/symbol/symbolTable.h"
#include "nasm/report/report.h"
#include "nasm/bitTools/bitTools.h"
#include "nasm/elf/elfFile.h"
#include "nasm/instruction/generator.h"

namespace dspnasm {

    class SymbolCollector : public dspnasm::NasmBaseVisitor {
    private:
        std::shared_ptr<ElfFile> m_elfFile;
        std::shared_ptr<SymbolTable> m_symbolTable; // 符号表
        std::string m_segmentName;   // 当前分析到的段名称
        u32 m_offset;   // 当前分析到的段偏移
        u32 m_assemblyAddress; // 当前分析到的汇编地址
        u32 m_curSize;  // 当前的指令尺寸

        // 保存当前分析完的一个段信息
        void saveSection();

    public:

        SymbolCollector(std::shared_ptr<SymbolTable> symbolTable, std::shared_ptr<ElfFile> elfFile);

        ~SymbolCollector() override = default;

        antlrcpp::Any visitDeclare(NasmParser::DeclareContext *ctx) override;

        antlrcpp::Any visitExpr(NasmParser::ExprContext *ctx) override;

        antlrcpp::Any visitItem(NasmParser::ItemContext *ctx) override;

        antlrcpp::Any visitFactor(NasmParser::FactorContext *ctx) override;

        antlrcpp::Any visitVal(NasmParser::ValContext *ctx) override;

        antlrcpp::Any visitNum(NasmParser::NumContext *ctx) override;

        antlrcpp::Any visitInstruction(NasmParser::InstructionContext *ctx) override;

        antlrcpp::Any visitProgram(NasmParser::ProgramContext *ctx) override;
    };
}

#endif //DSPNASM_SYMBOLCOLLECTOR_H
